package com.excemple.compose.ui.page.main

import androidx.compose.foundation.background
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.excemple.compose.constant.RouteNameConstant
import com.excemple.compose.ui.page.category.CategoryPage
import com.excemple.compose.ui.page.collection.CollectionPage
import com.excemple.compose.ui.page.home.HomePage
import com.excemple.compose.ui.page.profile.ProfilePage
import com.excemple.compose.ui.widgets.BottomNavBarWidget
import com.google.accompanist.insets.navigationBarsPadding
import com.google.accompanist.insets.statusBarsPadding

/**
 * App脚手架
 * Created on 2022/5/6.
 * @author tdq
 */
@Composable
fun AppScaffold() {
    val navController = rememberNavController()
    val navBackStackEntry by navController.currentBackStackEntryAsState()
    val currentDestination = navBackStackEntry?.destination

    Scaffold(
        modifier = Modifier
            .statusBarsPadding()
            .navigationBarsPadding(),
        bottomBar = {
            when (currentDestination?.route) {
                RouteNameConstant.homeRoute -> BottomNavBarWidget(navCtrl = navController)
                RouteNameConstant.categoryRoute -> BottomNavBarWidget(navCtrl = navController)
                RouteNameConstant.collectionRoute -> BottomNavBarWidget(navCtrl = navController)
                RouteNameConstant.profileRoute -> BottomNavBarWidget(navCtrl = navController)
            }
        },
        content = {
            NavHost(
                modifier = Modifier.background(MaterialTheme.colors.background),
                navController = navController,
                startDestination = RouteNameConstant.homeRoute
            ) {

                //登录
                composable(route = RouteNameConstant.loginRoute) {
                    LoginPage(navController = navController)
                }

                //首页
                composable(route = RouteNameConstant.homeRoute) {
                    HomePage(navController = navController)
                }

                //分类
                composable(route = RouteNameConstant.categoryRoute) {
                    CategoryPage(navController = navController)
                }

                //收藏
                composable(route = RouteNameConstant.collectionRoute) {
                    CollectionPage(navController = navController)
                }

                //我的
                composable(route = RouteNameConstant.profileRoute) {
                    ProfilePage(navController = navController)
                }
            }
        },

        )

}